package fr.sunnydale.android.geek.util;

import android.graphics.Rect;

/**
 * Graphical Utilities and constants.
 * @author pnicoli
 */
public class GUtils {

    /**
     * Scale relative to the dpi of the running system.
     */
    public static float SCALE;
    /**
     * Default border size of a tile. Usually 50 for HVGA.
     */
    public static float TILESIZE;

    /**
     * Gets a {@link Rect} scaled to the current dpi.
     * @param left
     *            {@link Rect#left}
     * @param top
     *            {@link Rect#top}
     * @param right
     *            {@link Rect#right}
     * @param bottom
     *            {@link Rect#bottom}
     * @return a {@link Rect}, scaled properly.
     */
    public static Rect getScaledRect(int left, int top, int right, int bottom) {
        return new Rect(Float.valueOf(left * SCALE).intValue(), Float.valueOf(top * SCALE).intValue(), Float.valueOf(
                right * SCALE).intValue(), Float.valueOf(bottom * SCALE).intValue());
    }

    /**
     * Gets a {@link Rect} scaled to the current dpi.
     * @param rect
     *            The {@link Rect} to transform.
     * @return a {@link Rect}, scaled properly.
     */
    public static Rect getScaledRect(Rect rect) {
        return getScaledRect(rect.left, rect.top, rect.right, rect.bottom);
    }

    public static TileCoord getTileFromRaw(float x, float y) {
        return new TileCoord(Float.valueOf((x - x % TILESIZE) / TILESIZE).intValue(), Float.valueOf(
                (y - y % TILESIZE) / TILESIZE).intValue());
    }
}
